package br.inatel.ec203.projeto.view;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class ValueSearchPanel extends JPanel {

	private static final long serialVersionUID = -6802539781009310942L;
	
	private JLabel valueLabel;
	private JTextField valueTextField;
	private JButton searchButton;
	
	private ValueSearchPanelListeners valueSearchPanelListeners;
	
	private GridBagConstraints valueLabelConstraints;
	private GridBagConstraints valueTextFieldConstraints;
	private GridBagConstraints searchButtonConstraints;
	
	public ValueSearchPanel() {
		initialize();
	}

	private void initialize() {
		setLayout(new GridBagLayout());
		add(getValueLabel(), getValueLabelConstraints());
		add(getValueTextField(), getValueTextFieldConstraints());
		add(getSearchButton(), getSearchButtonConstraints());
	}
	
	private JLabel getValueLabel() {
		if (valueLabel == null) {
			valueLabel = new JLabel();
			valueLabel.setText("Valor");
		}
		return valueLabel;
	}

	public JTextField getValueTextField() {
		if (valueTextField == null) {
			valueTextField = new JTextField();
		}
		return valueTextField;
	}

	private JButton getSearchButton() {
		if (searchButton == null) {
			searchButton = new JButton();
			searchButton.setText("Pesquisar");
			searchButton.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent e) {
					valueSearchPanelListeners.searchPerformed();
				}
			});
		}
		return searchButton;
	}

	private GridBagConstraints getValueLabelConstraints() {
		if (valueLabelConstraints == null) {
			valueLabelConstraints = new GridBagConstraints();
			valueLabelConstraints.gridx = 0;
			valueLabelConstraints.gridy = 0;
			valueLabelConstraints.insets = new Insets(5, 5, 5, 5);
		}
		return valueLabelConstraints;
	}

	private GridBagConstraints getValueTextFieldConstraints() {
		if (valueTextFieldConstraints == null) {
			valueTextFieldConstraints = new GridBagConstraints();
			valueTextFieldConstraints.gridx = 1;
			valueTextFieldConstraints.gridy = 0;
			valueTextFieldConstraints.ipadx = 300;
			valueTextFieldConstraints.fill = GridBagConstraints.HORIZONTAL;
			valueTextFieldConstraints.insets = new Insets(5, 5, 5, 5);
		}
		return valueTextFieldConstraints;
	}

	private GridBagConstraints getSearchButtonConstraints() {
		if (searchButtonConstraints == null) {
			searchButtonConstraints = new GridBagConstraints();
			searchButtonConstraints.gridx = 2;
			searchButtonConstraints.gridy = 0;
			searchButtonConstraints.insets = new Insets(5, 5, 5, 5);
		}
		return searchButtonConstraints;
	}
	
	public void addValueSearchPanelListeners(
			ValueSearchPanelListeners amountSearchPanelListeners) {
		this.valueSearchPanelListeners = amountSearchPanelListeners;
	}
}



















